<!--  -->
<template>
  <div class="userlist">
    <headers></headers>
    <!-- 表格 -->
    <el-table :data="tableData" style="width: 100%">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="商品名称">
              <span>{{ props.row.name }}</span> </el-form-item
            ><br />
            <el-form-item label="所属店铺">
              <span>{{ props.row.shop }}</span> </el-form-item
            ><br />
            <el-form-item label="商品 ID">
              <span>{{ props.row.id }}</span> </el-form-item
            ><br />
            <el-form-item label="店铺 ID">
              <span>{{ props.row.shopId }}</span> </el-form-item
            ><br />
            <el-form-item label="商品分类">
              <span>{{ props.row.category }}</span> </el-form-item
            ><br />
            <el-form-item label="店铺地址">
              <span>{{ props.row.address }}</span> </el-form-item
            ><br />
            <el-form-item label="商品描述">
              <span>{{ props.row.desc }}</span> </el-form-item
            ><br />
          </el-form>
        </template>
      </el-table-column>
      <el-table-column label="商品 ID" prop="id"> </el-table-column>
      <el-table-column label="商品价格" prop="total_amount"> </el-table-column>
      <el-table-column label="描述" prop="title"> </el-table-column>
    </el-table>
    <!-- 分页器 -->
    <div class="pagebox">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pagenow"
        layout=" prev, pager, next, jumper"
        :total="counts"
        :page-size="3"
      >
      </el-pagination>
      <el-pagination layout="total" :total="counts"> </el-pagination>
    </div>
  </div>
</template>

<script>
import Header from "./header";
import { getOrderslist, getAllordercount } from "../axios/api";
export default {
  data() {
    //这里存放数据
    return {
      tableData: [
        {
          id: 1,
          total_amount: "122",
          title: "支付成功",
        },
        {
          id: 1,
          total_amount: "122",
          title: "支付成功",
        },
        {
          id: 1,
          total_amount: "122",
          title: "支付成功",
        },
      ],
      pagenow: 1,
      counts: 0,
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //组件
  components: {
    headers: Header,
  },
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    getadminlist: function () {
      var start = this.pagenow;
      getOrderslist({ offset: (start - 1) * 3, limit: 3 }).then((res) => {
        this.tableData.forEach((item, index) => {
          item.id = "";
          item.amount = "";
          item.title = "";
        });
        res.forEach((item, index) => {
          this.tableData[index].id = item.id;
          this.tableData[index].amount = item.total_amount;
          this.tableData[index].title = item.status_bar.title;
        });
      });
      getAllordercount().then((res) => {
        this.counts = res.count;
      });
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pagenow = val;
      this.getadminlist();
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.getadminlist();
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style  lang='less'>
</style>